#pragma once

#include <QEventLoop>
#include <QMutex>
#include <QObject>
#include <QProcess>
#include <QString>
#include <QTextEdit>
#include <QThread>

class FaceRecognition : public QObject
{
    Q_OBJECT

public:
    static FaceRecognition &getInstance();
    ~FaceRecognition();
    void stopProcess();
    QString runFaceRecognition(bool symbol, const QString &knownFacesDir,
                               const QString &checkImagesDir, const QString &outputJsonPath,
                               int cpus = -1, double tolerance = 0.5, bool showDistance = true);
    void setOutputWidget(QTextEdit *output)
    {
        m_outputWidget = output;
    }

private:
    explicit FaceRecognition(QObject *parent = nullptr);
    void setExecutablePath(const QString &batchPath, const QString &singlePath);
    void appendOutput(const QString &text);

private:
    QMutex mutex;
    QString m_batchExecPath;
    QString m_singleExecPath;
    QString m_lastOutput;
    QProcess *m_currentProcess = nullptr;
    QTextEdit *m_outputWidget  = nullptr;
};
